/*
 * This class deals with obtaining the connection to the database.
 */
package Database;
 

import java.sql.*;

/**<P>Allows a user to connect to the cs342group4 database.
 * In addition, a user may close the connection with the database.</P>
 *
 * @author Kevin Boerboom
 */
public class DBConnection {
/** The database URL.  Needed for connectivity.
 */
    static String dbURL;

    /** The actual connection to the database.
     */
    static Connection conn;


/**Gets a connection for the cs342group4 database
 * @return the Connection to the cs342group4 database
 */
    public static Connection getConn(){
        if (conn == null){
            try{
                String db = "cs342group4";
                String pw = "p7037337";
                Class.forName("com.mysql.jdbc.Driver");
                dbURL = "jdbc:mysql://cs346.cs.uwosh.edu:4381/" + db;
                System.out.println("Attemping Connection");
                conn = DriverManager.getConnection(dbURL, db, pw);
                System.out.println("Connection Successful");
            }catch(ClassNotFoundException ex){
                System.out.println("Error: " + ex);
            }catch(SQLException ex){
                System.out.println("Error: " + ex);
            }
        } //else we are already connected
        return conn;
    }

    /**Closes the connection with the cs342group4 database
     */
    public static void closeConnection(){
        try {
            conn.close();
        } catch (SQLException ex) {
            System.out.println("Error " + ex);
        }
    }

}
